<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php 
if(isset($_POST["btn_dangnhap"]))
{
	$a = substr(rand(0,999),0,7);
	$a = md5(md5(md5(md5($a))));
	//echo $a;
	include("../../include/configuration.php");
	include("../../include/database.php");
	$obj_config = new Config();
	include_once("../../coms/xl_nguoidung.php");
	$admin = new xl_nguoidung();
	$ten =  $_POST['txt_tendangnhap'];
	$arr = $admin->Lay_email_theo_ten($ten);
	echo $arr['manguoidung'];
	echo $arr['email'];
	if(isset($arr['manguoidung']))
	{
		echo $_POST['txt_tendangnhap'];
		$matkhau = new xl_nguoidung();
		$kq=$matkhau->set_matkhau($a,$ten);
		echo $kq;
		if(isset($arr['tendangnhap']))
		{
			$from = 'info@giatthamviet.com';
			$to = $arr['email'];
			//echo $to;
			$subject = "Lấy lại mật khẩu" ;
			//echo $subject;
			$message = "Mật khẩu mới của bạn là : ".$a ;
			//echo $message;
			$header = "From: ".$from;
			//echo $header;
			//$to=" hotrolaptrinh@gmail.com ";
			if ( mail($to, $subject, $message, $header) ) 
			{
					echo "Email sent to $to!";
					//echo '<meta http-equiv="refresh" content="2;url=trangchu.php"  />';
			} 
			else 
			{
				echo "Error occured while sending email to $to!";
				//echo '<meta http-equiv="refresh" content="2;url=trangchu.php"  />';
			} 
		}
		else
		{
			echo "Tên đăng nhập không tồn tại";
			//echo '<meta http-equiv="refresh" content="10;url=trangchu.php"  />';
		}
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../../CSS/mystyle.css">
<title>ADMIN</title>
</head>

<body>
<div id="page">
<div id="content">
<form method="post" name="login" onSubmit="" action="laylaimatkhau.php">
<table align="center" cellpadding="5" cellspacing="0" border="0" style="color:#FFFFFF;" width="80%">
	<tr>
    	<td rowspan="4" width="55%"><img src="../../Images/web/logo_admin.png" /></td>
    </tr>
	<tr>
    	<td colspan="2" align="center"  style="color:#f9d765; font-size:16px"><b>Lấy lại mật khẩu</b></td>
    </tr>
    <tr>
    	<td>Tên đăng nhập:</td>
        <td><input name="txt_tendangnhap" type="text" /></td>
    </tr>
    <tr>
    	<td colspan="2" align="center">
        	<input name="btn_dangnhap" type="submit" value="Lấy lại mật khẩu" class="button small greenbold"/>
            <input name="btn_thoat" type="button" value="Trở lại" onClick="window.location.href='index.php'" class="button small greenbold"/>
        </td>
    </tr>
</table></form>
</div>
</div>
	<?php
	/* include("../../include/configuration.php");
	include("../../include/database.php");
	$obj_config = new Config();
	include_once("../../coms/xl_admin.php");
	$nv = new xl_admin();
	$arr_nv = $nv->Load_nv();
	
	$user = $_POST['txt_tentruycap'];
	$pass = $_POST['txt_matkhau'];
	
	if(isset($_POST['btn_dangnhap']))
	{
		for($i=0; $i<count($arr_nv); $i++)
		{
			$row = $arr_nv[i];
			$flag1=0;
			$flag2=0;
			if($row['TenTruyCap'] == $user)
				$flag1 = 1;
			if($row['MatKhau'] == $pass)
				$flag2 = 1;
		}		
	} */
		?>


</body>
</html>
